package edu.henu.personnel.dao;

import edu.henu.personnel.entity.Catalog;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: PersonnelProject
 * @description: 文章分类DAO
 * @author: zhuyang
 */

@Repository
public interface CatalogDao {

    // 查询所有的栏目
    @Select("select * from t_catalog")
    List<Catalog> findAllCatalog();

    // 查询所有的固定总栏目
    @Select("select distinct cmemo from t_catalog")
    List<String> findAllCmemo();

    // 根据cid查询相应的栏目信息
    @Select("select * from t_catalog where cid = #{cid}")
    Catalog findCatalogById(Integer cid);

    // 插入新的栏目
    @Insert("insert into t_catalog(cname, cmemo) values " +
            "(#{cname}, #{cmemo})")
    int insertCatalog(Catalog catalog);

    // 修改栏目信息
    @Update("update t_catalog set " +
            "cname=#{cname}," +
            "cmemo=#{cmemo} " +
            "where cid = #{cid}")
    int updateCatalog(Catalog catalog);

    // 根据栏目cid删除指定栏目
    @Delete("delete from t_catalog where cid = #{cid}")
    int deleteCatalogById(@Param("cid")Integer cid);


    // 根据cid查询相应的栏目名
    @Select("select cname from t_catalog where cid = #{cid}")
    String findCatalogNameById(Integer cid);

    // 根据栏目名查询相应的栏目信息
    @Select("select * from t_catalog where cname = #{cname}")
    Catalog findCatalogByName(String cname);

    // 根据总栏目名查询所有的子栏目信息
    @Select("select * from t_catalog where cmemo = #{cmemo}")
    List<Catalog> findAllCatalogInfoByMemo(String cmemo);
}
